$(function () {
    var sale_datagrid = $("#sale_datagrid");
    var bar_dialog = $("#bar_dialog");
    var pic_dialog = $("#pic_dialog");
    sale_datagrid.datagrid({
        url: '/salesChart/query',
        fit: true,
        fitColumns: true,//自适应宽度
        pagination: true,//显示分页栏
        toolbar: '#tb',
        columns: [
            [
                {field: 'groupBy', title: '分组类型', width: 80}
                ,
                {field: 'amount', title: '销售总金额', width: 80}
            ]
        ]
    });

    /*柱状图信息的弹窗*/
    bar_dialog.dialog({
        width: 800,
        height: 680,
        closed: true,
        modal: true,
        buttons: '#bar_btn',
        onClose: function () {
        }
    });
    /*柱状图信息的弹窗*/
    pic_dialog.dialog({
        width: 800,
        height: 680,
        closed: true,
        modal: true,
        buttons: '#pic_btn',
        onClose: function () {
        }
    });


    //统一事件绑定
    $("a[data-cmd]").click(function () {
        var methodName = $(this).data("cmd");
        methodObj[methodName]();
    });
    //统一事件管理
    var methodObj = {
        query: function () {
            //获取输入框值
            var groupBy = $("#groupBy option:selected").val();
            sale_datagrid.datagrid('load', {
                groupBy: groupBy
            })
        },
        bar: function () {
            var groupBy = $("#groupBy option:selected").val();
            $("#barTable").prop("src","/salesChart/saleByBar?groupBy="+groupBy);
            bar_dialog.dialog('open');
            bar_dialog.dialog('setTitle', '销售报表');
        },
        pic: function () {
            var groupBy = $("#groupBy option:selected").val();
            $("#picTable").prop("src","/salesChart/saleByPic?groupBy="+groupBy);
            pic_dialog.dialog('open');
            pic_dialog.dialog('setTitle', '销售报表');
        },
        cancelBar: function () {
            // pic_dialog.dialog('close');
            bar_dialog.dialog('close');
        },
        cancelPic: function () {
            pic_dialog.dialog('close');
            // bar_dialog.dialog('close');
        }

    };
});